package com.paul.sys.controller.back;

import com.paul.sys.model.FieldParkInfo;
import com.paul.sys.service.FieldParkInfoService;
import com.paul.sys.tools.PageData;
import com.paul.sys.util.ParamUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by yangjianbo on 2015/11/4.
 */
@Controller
@RequestMapping("/back/fieldpark/")
public class FieldParkController {
    private static Logger logger = Logger.getLogger(RoadParkController.class);
    @Autowired
    private FieldParkInfoService fieldParkInfoService;
    @RequestMapping("ismenu/fieldpark")
    public ModelAndView fieldpark() throws Exception {
        ModelAndView view = new ModelAndView("back/fieldPark/fieldPark-list");
        Integer totalselect = fieldParkInfoService.countAll(new HashMap());
        view.addObject("total", totalselect);
        return view;
    }
    @ResponseBody
    @RequestMapping("list")
    public Map<String, Object> listPtstaff(HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>();

        try {
            ParamUtil util = new ParamUtil(request);
            Map<String, String> param = util.getParamMap();
            PageData pageData = fieldParkInfoService.listByPage(param);
            result.put("totalRows", pageData.getPageBean().getTotalNum());
            result.put("curPage", param.get("curPage"));
            result.put("data", pageData.getListData());
            result.put("success", true);
        } catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
        }

        return result;
    }

    /**
     * 得到停车场总数
     * @param request
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("gettotal")
    public Map<String, Object> gettotal(HttpServletRequest request) throws Exception {
        Map<String, Object> result = new HashMap<String, Object>();
        ParamUtil util = new ParamUtil(request);
        Map<String, String> param = util.getParamMap();
        Integer totalselect = fieldParkInfoService.countAll(param);
        result.put("total", totalselect);
        return result;
    }
    /**
     * 返回停车场编辑视图
     * @param unid
     * @return
     * @throws Exception
     */
    @RequestMapping("edit_page{unid}")
    public ModelAndView fileParkEditPage(@PathVariable String unid) throws Exception {
        ModelAndView view = new ModelAndView("back/fieldPark/fieldPark-edit");
        FieldParkInfo fieldParkInfo=this.fieldParkInfoService.selectByPrimaryKey(unid);
        view.addObject("fieldParkInfo",fieldParkInfo);
        return view;
    }
    /**
     * 返回地图
     * @param
     * @return
     * @throws Exception
     */
    @ResponseBody
    @RequestMapping("localmap")
    public ModelAndView localMap(String lng,String lat) throws Exception {
        ModelAndView view = new ModelAndView("back/fieldPark/localMap");
        view.addObject("lng",lng);
        view.addObject("lat",lat);
        return view;
    }

    @ResponseBody
    @RequestMapping(value = "doupdate",method = RequestMethod.POST)
    public Map<String,Object> menuUpdate(FieldParkInfo fieldParkInfo) throws Exception {
        Map<String,Object> result = new HashMap<String,Object>();
        fieldParkInfoService.updateByPrimaryKey(fieldParkInfo);
        result.put("status",0);
        return result;
    }
}
